package com.yegs.jltqc.controller;

import com.yegs.jltqc.TO.MoldPageQuery;
import com.yegs.jltqc.TO.NamePageQuery;
import com.yegs.jltqc.VO.Formwork;
import com.yegs.jltqc.VO.Project;
import com.yegs.jltqc.config.Msg;
import com.yegs.jltqc.service.FormworkService;
import com.yegs.jltqc.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/formwork")
public class FormworkController {

    @Autowired
    private FormworkService formworkService;

    @PostMapping("/save")
    public Msg save(@RequestBody Formwork formwork){
        try{
            return Msg.success("data",formworkService.save(formwork));
        }catch (Exception e){
            return Msg.error(e.getMessage());
        }
    }

    @GetMapping("/list")
    public Msg list(){
        return Msg.success("list",formworkService.list());
    }

    @GetMapping("/get")
    public Msg get(@RequestParam Long id){
        return Msg.success("data",formworkService.get(id));
    }

    @GetMapping("/getFormworkByMold")
    public Msg getFormworkByMold(@RequestParam String mold){
        return Msg.success("data",formworkService.getFormworkByMold(mold));
    }
    @GetMapping("/getLast")
    public Msg getLast(@RequestParam(required = false) Long id, @RequestParam String mold){
        return Msg.success("data",formworkService.getLast(id, mold));
    }
    @GetMapping("/getNext")
    public Msg getNext(@RequestParam(required = false) Long id, @RequestParam String mold){
        return Msg.success("data",formworkService.getNext(id, mold));
    }

    @GetMapping("/del")
    public Msg del(@RequestParam Long id){
        formworkService.del(id);
        return Msg.success();
    }
    @PostMapping("/query")
    public Msg query(@RequestBody MoldPageQuery query){
        return Msg.success("page",formworkService.query(query));
    }




}
